<?php
header("Content-Type:application/json;charset=UTF-8");

$connt = mysqli_connect('localhost','root','root','cmycgs');
if(!$connt)
{
    echo json_encode(['code'=>0,'msg'=>'连接失败']);
}
$sql = 'SELECT emp.name,count(*) as total
        FROM emp join dept
        on emp.dept_id = dept.id
        GROUP BY dept_id';
$query = mysqli_query($connt,$sql);
$data = mysqli_fetch_all($query,MYSQLI_ASSOC);

$sql1 = 'SELECT COUNT(sex) as value,sex as name from emp GROUP BY sex';
$query1 = mysqli_query($connt,$sql1);
$res = mysqli_fetch_all($query1,MYSQLI_ASSOC);

$sql2 = 'SELECT salary,time,year FROM salary where name = "张三" ';
$query2 = mysqli_query($connt,$sql2);
$zx = mysqli_fetch_all($query2,MYSQLI_ASSOC);

    $xData = [];
    $yData = [];
    $zxData = [];
    $zxData1 = [];
    foreach ($data as $val)
    {
        $xData[] = $val['name'];
        $yData[] = $val['total'];
    }
    foreach ($zx as $val)
    {
        $zxData[] = $val['salary'];
        $zxData1[] = $val['time'].'.'.$val['year'];
    }
    if($data && $res)
    {
        echo json_encode(['code'=>1,'msg'=>'返回数据','data'=>[
            'x'=>$xData,
            'y'=>$yData,
            'bt'=>$res,
            'zx'=>$zxData,
            'zx1'=>$zxData1
        ]]);
    }
